package com.youdoneed.friends.recommanderFacePicture;

import com.youdoneed.base.application.ResultMessage;
import com.youdoneed.base.pagination.Page;
import com.youdoneed.base.pagination.Paging;
import com.youdoneed.friends.model.RecommandFacePicture;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by lid on 2017/11/21 0021.
 * 推荐人脸照控制类
 */
@RestController
@RequestMapping("/recommandFacePicture")
@Api(description = "推荐人脸照控制类")
public class RecommandFacePictureController {

    private static final Logger logger = LoggerFactory.getLogger(RecommandFacePictureController.class);

    @Autowired
    private RecommandFacePictureService recommandFacePictureService;

    @RequestMapping(value = "/getAllPicturesByPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台分页获取所有推荐人脸照", value = "后台分页获取所有推荐人脸照")
    public ResultMessage<Page<RecommandFacePicture>> getAllPicturesByPage(Paging paging) {
        return new ResultMessage<>(recommandFacePictureService.getAllPicturesByPage(paging));
    }

    @RequestMapping(value = "/addPicture", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台添加推荐人脸照", value = "后台添加推荐人脸照")
    public ResultMessage<?> addPicture(@ApiParam("图片Url") @RequestParam String pictureUrl,
                                       @ApiParam("备注") @RequestParam String mark) {
        recommandFacePictureService.addPicture(pictureUrl, mark);
        return new ResultMessage<>("保存推荐人脸照成功！");
    }

    @RequestMapping(value = "/deletePicture", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "删除推荐人脸照", value = "删除推荐人脸照")
    public ResultMessage<?> deletePicture(@ApiParam("图片id") @RequestParam String facePictureId) {
        recommandFacePictureService.deletePicture(facePictureId);
        return new ResultMessage<>("删除推荐人脸照成功！");
    }

    @RequestMapping(value = "/updatePicture", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台更新人脸照", value = "后台更新人脸照")
    public ResultMessage<?> updatePicture(@ApiParam("图片id") @RequestParam String facePictureId,
                                          @ApiParam("图片Url") @RequestParam(required = false) String pictureUrl,
                                          @ApiParam("备注") @RequestParam(required = false) String mark) {
        recommandFacePictureService.updatePicture(facePictureId, pictureUrl, mark);
        return new ResultMessage<>("修改推荐人脸照成功！");
    }

    @RequestMapping(value = "/changeSort", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "调整人脸照顺序", value = "调整人脸照顺序")
    public ResultMessage<?> changeSort(@ApiParam("图片id") @RequestParam String facePictureId,
                                       @ApiParam("方向！ up 是向上， down是向下") @RequestParam String direction) {
        recommandFacePictureService.changeSort(facePictureId, direction);
        return new ResultMessage<>("调整人脸照顺序成功！");
    }
}
